﻿@inherits AdminCompontentBase

<DefaultSheetDialog Value="Visible" ValueChanged=UpdateVisible Title="@T("Edit User")">
    <MForm Model=User EnableValidation EnableI18n>
        <AutoHeight Overflow AutoClass="mt-6">
            <HeaderContent>
                <div class="d-flex">
                    <div class="mx-auto text-center">
                        <UploadAvatar Size="80" @bind-Value="User.Avatar" WhenFileChangeUpload />
                        <SNameTextField @bind-Value="User.DisplayName" Placeholder="@T("Give him a nickname!")" style="width:212px;" />
                    </div>
                </div>
            </HeaderContent>
            <AutoHeightContent>
                <DefaultTitle Class="mb-4">@T("BasicInformation")</DefaultTitle>
                <div class="mb-6">
                    <ButtonGroup @bind-Value="User.Gender" TValue="GenderTypes" />
                </div>
                <MRow>
                    <MCol>
                        <STextField @bind-Value="User.Name" Label="@T("Name")" />
                    </MCol>
                    <MCol>
                        <STextField @bind-Value="User.PhoneNumber" Required Label="@T("PhoneNumber")" />
                    </MCol>
                </MRow>
                <MRow>
                    <MCol>
                        <STextField @bind-Value="User.CompanyName" Label="@T("CompanyName")" />
                    </MCol>
                    <MCol>
                        <STextField @bind-Value="User.Email" Label="@T("Email")" />
                    </MCol>
                </MRow>
                <MRow>
                    <MCol>
                        <STextField Required Readonly=CanUpdateAccount @bind-Value="User.Account" Label="@T("Account")" />
                    </MCol>
                    <MCol>
                        <SGeneratePassword Value="@UserPassword.Password" ValueChanged="ResetUserPasswordAsync" />
                    </MCol>
                </MRow>
                <DefaultTitle>@T("DetailInformation")</DefaultTitle>
                <MRow>
                    <MCol>
                        <STextField @bind-Value="User.IdCard" Label="@T("IdCard")" />
                    </MCol>
                    <MCol>
                        <STextField @bind-Value="User.Address.Address" Label="@T("Address")" />
                    </MCol>
                </MRow>
                <MRow>
                    <MCol>
                        <STextField @bind-Value="User.Department" Label="@T("Department")" />
                    </MCol>
                    <MCol>
                        <STextField @bind-Value="User.Position" Label="@T("Position")" />
                    </MCol>
                </MRow>
                <Authorization Avatars=UserDetail.ThirdPartyIdpAvatars />
                <Record Creator="@UserDetail.Creator" CreationTime="@UserDetail.CreationTime" Modifier="@UserDetail.Modifier" ModificationTime="@UserDetail.ModificationTime" />
            </AutoHeightContent>
            <FooterContent>
                 <div class="d-flex mt-6">
                    <EnableSwitch @bind-Value="User.Enabled" />
                    <MSpacer></MSpacer>
                    <SButton Class="mr-6 btn" Text Color="error" OnClick=OpenRemoveUserDialog>@T("Delete")</SButton>
                    <SButton Color="primary" Medium OnClick="async() => await UpdateUserAsync(context)">@T("Save")</SButton>
                </div>
            </FooterContent>
        </AutoHeight>
    </MForm>
</DefaultSheetDialog>
